// 导航栏滚动效果
window.addEventListener('scroll', function() {
  const navbar = document.querySelector('.navbar');
  if (window.scrollY > 50) {
    navbar.classList.add('scrolled');
  } else {
    navbar.classList.remove('scrolled');
  }
});

// 轮播动画效果
const carousel = document.querySelector('#carouselExampleCaptions');
carousel.addEventListener('slid.bs.carousel', function() {
  // 重置动画元素的状态
  const activeItem = this.querySelector('.carousel-item.active');
  const captionElements = activeItem.querySelectorAll('.carousel-caption h1, .carousel-caption p, .carousel-caption .btn');
  
  captionElements.forEach(el => {
    el.style.opacity = '0';
    el.style.transform = 'translateY(20px)';
    
    // 重新触发动画
    setTimeout(() => {
      el.style.transition = 'opacity 1s ease, transform 1s ease';
      el.style.opacity = '1';
      el.style.transform = 'translateY(0)';
    }, 50);
  });
});

// 平滑滚动
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  anchor.addEventListener('click', function (e) {
    e.preventDefault();
    
    const targetId = this.getAttribute('href');
    if (targetId === '#') return;
    
    const targetElement = document.querySelector(targetId);
    if (targetElement) {
      window.scrollTo({
        top: targetElement.offsetTop - 70,
        behavior: 'smooth'
      });
      
      // 关闭移动设备上的导航菜单
      const navbarCollapse = document.querySelector('.navbar-collapse');
      if (navbarCollapse.classList.contains('show')) {
        const toggler = document.querySelector('.navbar-toggler');
        toggler.click();
      }
    }
  });
});